package com.pm.controller.file;

import com.pm.common.Response;
import com.pm.common.annotation.CurrentUser;
import com.pm.common.annotation.MyLog;
import com.pm.common.annotation.UserLoginToken;
import com.pm.common.exception.ExpCodeState;
import com.pm.entity.po.file.DailyFileLib;
import com.pm.entity.po.file.FileLib;
import com.pm.entity.po.security.User;
import com.pm.service.file.DailyFileLibService;
import com.pm.service.file.DailyFileTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(tags = "日常文件")
@UserLoginToken
@RestController
@RequestMapping("/DailyFileLibController")
public class DailyFileLibController {
    @Autowired
    DailyFileTypeService dailyFileTypeService;
    @Autowired
    DailyFileLibService dailyFileLibService;

    @ApiOperation("新增接口")
    @PostMapping("/addFile")
    @ResponseBody
    @MyLog(value = "日常文件库添加")
    public Response<Integer> add(@RequestBody DailyFileLib dailyFileLib, @CurrentUser User user) {
        Response<Integer> response = null;
        dailyFileLib.setUserId(user.getUserId());
        Integer result = dailyFileLibService.add(dailyFileLib);
        if (result > 0) {
            response = new Response<>(ExpCodeState.add_data_success, result);
        } else {
            response = new Response<>(ExpCodeState.add_data_failed);
        }
        return response;
    }


    @ApiOperation("删除附件")
    @PostMapping("/deleteDailyFileLib")
    @ResponseBody
    @MyLog(value = "删除附件")
    public Response<Integer> deleteDailyFileLib(@RequestParam("id") Integer id) {
        boolean res = dailyFileLibService.deleteDailyFileLib(id);
        if (res) {
            return new Response<>(ExpCodeState.remove_data_success);
        } else {
            return new Response<>(ExpCodeState.remove_data_failed);
        }
    }

}
